Total Complexity | 2 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
6 | |||
7 | @QueryHandler(GetSchoolVouchersQuery) |
||
8 | export class GetSchoolVouchersQueryHandler { |
||
9 | constructor( |
||
10 | @Inject('IVoucherRepository') |
||
11 | private readonly voucherRepository: IVoucherRepository |
||
12 | ) {} |
||
13 | |||
14 | public async execute(query: GetSchoolVouchersQuery): Promise<SchoolUserView[]> { |
||
15 | const schoolUserViews: SchoolUserView[] = []; |
||
16 | const vouchers = await this.voucherRepository.findBySchool(query.schoolId); |
||
17 | |||
18 | for (const voucher of vouchers) { |
||
19 | schoolUserViews.push( |
||
20 | new SchoolUserView( |
||
21 | voucher.getId(), |
||
22 | voucher.getEmail(), |
||
23 | 'voucher' |
||
24 | ) |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | return schoolUserViews; |
||
29 | } |
||
31 |